<?php
include "lang.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Gia An</title>
        <script>
            function updateQty(qty, pid){
                window.location.href="../action/UpdateProductFromCartAction.php?n="+pid+"&q="+qty;
            }
            function clearProductFromCart(pid){
                window.location.href="../action/DeleteProductFromCartAction.php?n="+pid;
            }
        </script>
        <?php
        include ("import.php");
        include ("../service/ProductService.php");
        ?>
    </head>
    <body>
        <?php include("floating-panel.php"); ?>
        <div class="wrapper">
            <?php include("header.php"); ?>  
            <div class="main_body">
                <div class="content_box no_background">
                    <div id="TabbedPanels1" class="TabbedPanels">
                        <ul class="TabbedPanelsTabGroup">
                            <li class="TabbedPanelsTab" tabindex="0">
                                <?php echo $langs["cart.cart"]; ?>
                            </li>
                        </ul>
                        <div class="TabbedPanelsContentGroup">
                            <div class="TabbedPanelsContent">
                                <table cellspacing="0" class="cart_table">
                                    <tr>
                                        <th><?php echo $langs["cart.no"]; ?></th>
                                        <th><?php echo $langs["cart.productAndCode"]; ?></th>
                                        <th><?php echo $langs["cart.price"]; ?></th>
                                        <th><?php echo $langs["cart.qty"]; ?></th>
                                        <th><?php echo $langs["cart.cost"]; ?></th>
                                    </tr>
                                    <?php
                                    if (isset($_SESSION['cart'])) {
                                        //Cart existed
                                        $cart = $_SESSION['cart'];
                                    } else {
                                        $cart = array();
                                        $_SESSION['cart'] = $cart;
                                    }
                                    $count = 1;
                                    $total = 0;
                                    if (count($cart) > 0) {
                                        foreach ($cart as $k => $v) {
                                            $product = mysql_fetch_array(getProduct($k));
                                            ?>
                                            <tr>
                                                <td><?php echo $count;
                                    $count++; ?></td>
                                                <td><?php echo $lang == "EN" ? $product["PRO_NAME_EN"] : $product["PRO_NAME_VN"];
                                    echo "-" . $product["PRO_CODE"]; ?></td>
                                                <td><?php echo number_format($product["PRO_PRICE"]); ?></td>
                                                <td>
                                                    <input type="text" name="" id="qty<?php echo $product["PRO_ID"]; ?>" value="<?php echo $v; ?>" class="quantity_field"/>
                                                    <img src="../images/layout/save-icon.png" width="12" height="12" onclick="updateQty(document.getElementById('qty<?php echo $product["PRO_ID"]; ?>').value,<?php echo $product["PRO_ID"]; ?>)"/>
                                                    <img src="../images/layout/delete-icon.png" width="12" height="12" onclick="clearProductFromCart(<?php echo $product["PRO_ID"]; ?>)"/>
                                                </td>
                                                <td><?php $tempPrice = $v * $product["PRO_PRICE"];
                                    $total = $total + $tempPrice;
                                    echo number_format($tempPrice); ?></td>
                                            </tr>
                                            <?php
                                        }
                                        ?>
                                        <?php
                                    } else {
                                        ?>
                                        <tr><td colspan="5">Không có sản phẩm trong giỏ hàng</td></tr>
                                            <?php
                                        }
                                        ?>
                                    <tr>
<?php
if ($total > 0) {
    ?>
                                            <td colspan="4" align="right"><span class="red"><?php echo $langs["cart.total"]; ?></span></td>
                                            <td><span class="red"><?php echo number_format($total); ?></span></td>
    <?php
}
?>
                                    </tr>
                                </table>

                                <a href="index.php" class="button long right"><?php echo $langs["cart.continueShop"]; ?></a>
                                <?php
                                if (count($cart) > 0) {
                                    ?>
                                    <a href="order.php" class="button long right"><?php echo $langs["cart.order"]; ?></a>
    <?php
}
?>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
<?php include("footer.php"); ?>
        <script type="text/javascript">
            <!--
            var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
            //-->
        </script>
    </body>
</html>
